package com.spark.data

import com.google.gson.Gson
import com.spark.common.BaseFragment
import com.spark.common.Const
import com.spark.common.ext.report
import com.spark.common.ext.toast
import com.spark.common.ext.wrapIO
import com.spark.common.net.Http
import com.spark.common.net.toJsonBody
import com.spark.data.model.BorrowApplyResultModel

class BorrowApplyFragment : BaseFragment() {
    override fun contentResId(): Int {
        return R.layout.frag_borrow_apply
    }



    fun apply() {
        val param = mutableMapOf(
                Pair(Const.qr_editionId, ""),
                Pair(Const.qr_borrowDay, ""),
                Pair(Const.qr_borrowRemark, "")
        )
        activity?.apply {
            Http.request()
                    .rxPost("${Const.base_url}${Const.act_apply_borrow}", param.toJsonBody())
                    .wrapIO()
                    .subscribe(
                            {
                                Gson().fromJson(it, BorrowApplyResultModel::class.java)?.apply {
                                    toast(msg)
                                    if (code == "200")
                                        pop()
                                }
                            },
                            {
                                it.printStackTrace()
                                report(it)
                            },
                            {},
                            {
                                dispose = it
                            }
                    )
        }
    }

}